//package com.lab303.powerproject.strategy.impl;
//
//import com.lab303.powerproject.entity.HistoryData;
//import com.lab303.powerproject.entity.StrategyOutput;
//import com.lab303.powerproject.strategy.BaseWorkStrategy;
//import com.lab303.powerproject.strategy.WorkStrategyInterface;
//import com.lab303.powerproject.strategy.enums.StrategyEnums;
//import com.lab303.powerproject.strategy.pojo.*;
//import com.lab303.powerproject.strategy.pojo.device.ConsumeDevice;
//import com.lab303.powerproject.strategy.pojo.device.StorageDevice;
//import com.lab303.powerproject.strategy.pojo.device.SupplyDevice;
//import com.lab303.powerproject.strategy.utils.DateUtils;
//import com.lab303.powerproject.strategy.utils.ElectricityPriceUtil;
//import org.springframework.stereotype.Component;
//
//import java.io.IOException;
//import java.text.ParseException;
//import java.util.*;
//
///**
// * 舒适度优先策略
// */
//@Component
//public class ComfortPriorityStrategy extends BaseWorkStrategy implements WorkStrategyInterface {
//    @Override
//    public Map<String, Object> generate(Date date) throws IOException, ParseException {
//        Integer graphId = getGraphId();
//
//        // 获取电价信息
////        ElectricityPriceUtil utils = getElectricityUtil(graphId);
//        ElectricityPriceUtil utils = null;
//        // 获取峰谷平电价
//        double[] prices = utils.minMiddleMaxPrice();
//        // 获取（电价：索引）
//        Map<Double, List<String>> priceListWithIndex = utils.getPriceListWithIndex();
//
//        // 组建设备信息（通过RelationShipService知晓关系）
//        // 获取PathAndNode
//        Map<String, String> info = getDeviceInfo(graphId);
//        // 节点
//        String nodes = info.get("node");
//        // 路径
//        String path = info.get("edge");
//        // PathAndNode
//        com.lab303.powerproject.strategy.pojo.PathAndNode pathAndNode = new com.lab303.powerproject.strategy.pojo.PathAndNode(nodes, path);
//
//
//        // 组建设备信息（以后采取从数据库中读的形式）
//        // 用能设备
//        ConsumeDevice consumeDevice = new ConsumeDevice(207, "末端");
//        // 供能设备
//        SupplyDevice doubleMachine = new SupplyDevice(203, "双工况冷水机组", utils.getPriceListSize());
//        SupplyDevice normalMachine = new SupplyDevice(204, "常温冷水机组", utils.getPriceListSize());
//        SupplyDevice airMachine = new SupplyDevice(200, "空气源热泵机组", utils.getPriceListSize());
//        // 储能设备
//        StorageDevice iceStorage = new StorageDevice(206, "冰蓄能装置", doubleMachine, utils.getPriceListSize(), 0.95);
//        // 绑定供能设备和用能设备
//        consumeDevice.addSupply(doubleMachine, normalMachine, airMachine, iceStorage);
//        Calendar tomorrow = DateUtils.plusOrMinusDay(date, 1);
//
//        // 所预测的明日的天气数据（从数据库中读取）
//        com.lab303.powerproject.strategy.pojo.DayWeather tomorrowWeather = getForecastWeatherByDate(tomorrow.getTime());
//        if (tomorrowWeather == null) {
//            // 如果获取到的温度数据为空，设置一个默认值
//            tomorrowWeather = new com.lab303.powerproject.strategy.pojo.DayWeather();
//            tomorrowWeather.setTempavg(28D);
//            tomorrowWeather.setTemphigh(28D);
//        } else {
//            tomorrowWeather.setTempavg();
//        }
//
//        double tem = tomorrowWeather.getTemphigh();
//
//        Strategy s1 = new Strategy(2, iceStorage.getStorageInfo(),1, iceStorage);
//        Strategy s2 = new Strategy(1, iceStorage.getSupplyInfo(), 2, iceStorage);
//        Strategy s3 = new Strategy(1, normalMachine.getSupplyInfo(), 3, normalMachine);
//        Strategy s4 = new Strategy(1, doubleMachine.getSupplyInfo(), 4, doubleMachine);
//        Strategy s5 = new Strategy(1, airMachine.getSupplyInfo(), 5, airMachine);
//
//        List<com.lab303.powerproject.strategy.pojo.StrategyComb> strategyCombList = new ArrayList<>();
//        strategyCombList.addAll(Arrays.asList(
//                new com.lab303.powerproject.strategy.pojo.StrategyComb(s1)
//                ,new com.lab303.powerproject.strategy.pojo.StrategyComb(s2)
//                ,new com.lab303.powerproject.strategy.pojo.StrategyComb(s3)
//                ,new com.lab303.powerproject.strategy.pojo.StrategyComb(s4)
//                ,new com.lab303.powerproject.strategy.pojo.StrategyComb(s5)
//                ,new com.lab303.powerproject.strategy.pojo.StrategyComb(6, s1, s3)
//                ,new com.lab303.powerproject.strategy.pojo.StrategyComb(7, s1, s5)
//                ,new com.lab303.powerproject.strategy.pojo.StrategyComb(8, s2, s3)
//                ,new com.lab303.powerproject.strategy.pojo.StrategyComb(9, s2, s4)
//                ,new com.lab303.powerproject.strategy.pojo.StrategyComb(10, s2, s5)
//                ,new com.lab303.powerproject.strategy.pojo.StrategyComb(11, s3, s4)
//                ,new com.lab303.powerproject.strategy.pojo.StrategyComb(12, s3, s5)
//                ,new com.lab303.powerproject.strategy.pojo.StrategyComb(13, s4, s5)
//                ,new com.lab303.powerproject.strategy.pojo.StrategyComb(14, s2, s3, s4)
//                ,new com.lab303.powerproject.strategy.pojo.StrategyComb(15, s2, s3, s5)
//                ,new com.lab303.powerproject.strategy.pojo.StrategyComb(16, s2, s4, s5)
//                ,new com.lab303.powerproject.strategy.pojo.StrategyComb(17, s3, s4, s5)
//                ,new com.lab303.powerproject.strategy.pojo.StrategyComb(18, s2, s3, s4, s5)
//        ));
//
//        Integer holidayStatus = isHolidayByDate(tomorrow.getTime());
//        if (holidayStatus == 2) {
//            // 节假日时间段无策略
//        } else if (holidayStatus == 1) {
//            // 周末时间段无策略
//        } else {
//            Map<Double, com.lab303.powerproject.strategy.pojo.StrategyComb> combsMap = getStrategyCombMap(tem, prices, strategyCombList, new String[]{"1,8,8","1,14,14","1,18,18"});
//            // 遍历峰谷平电价
//            for (double price: prices) {
//                List<String> dateList = priceListWithIndex.get(price);
//                for (String dateStr: dateList) {
//                    Integer startIndex = Integer.parseInt(dateStr.split("~")[0]);
//                    Integer endIndex = Integer.parseInt(dateStr.split("~")[1]);
//
//                    com.lab303.powerproject.strategy.pojo.StrategyComb comb = combsMap.get(price);
//                    comb.setFlagAllBindingDevice(startIndex, endIndex);
//                }
//            }
//        }
//
//        // 冰蓄能
//        Map<Integer, Strategy> iceStorageMapping = new HashMap<>();
//        iceStorageMapping.put(1, s1);
//        iceStorageMapping.put(2, s2);
//        List<StrategyOutput> iceStorageOutput = getStrategyOutList(iceStorage, date, iceStorageMapping, StrategyEnums.COMFORT_TYPE.getType());
//        // 双工况冷水机组
//        Map<Integer, Strategy> doubleMachineMapping = new HashMap<>();
//        doubleMachineMapping.put(1, s4);
//        List<StrategyOutput> doubleMachineOutput = getStrategyOutList(doubleMachine, date, doubleMachineMapping,StrategyEnums.COMFORT_TYPE.getType());
//        // 常温冷水机组
//        Map<Integer, Strategy> normalMachineMapping = new HashMap<>();
//        normalMachineMapping.put(1, s3);
//        List<StrategyOutput> normalMachineOutput = getStrategyOutList(normalMachine, date, normalMachineMapping,StrategyEnums.COMFORT_TYPE.getType());
//        // 空气源热泵机组
//        Map<Integer, Strategy> airMachineMapping = new HashMap<>();
//        airMachineMapping.put(1, s5);
//        List<StrategyOutput> airMachineOutput = getStrategyOutList(airMachine, date, airMachineMapping,StrategyEnums.COMFORT_TYPE.getType());
//
//        List<StrategyOutput> strategyOutputList = new ArrayList<>();
//        strategyOutputList.addAll(iceStorageOutput);
//        strategyOutputList.addAll(doubleMachineOutput);
//        strategyOutputList.addAll(normalMachineOutput);
//        strategyOutputList.addAll(airMachineOutput);
//
//        // 自动去除所有无关依赖
//        removeNodeOrEdgeAllDevice(pathAndNode, consumeDevice, doubleMachine, normalMachine, airMachine, iceStorage);
//
//        Map<String, Object> ans = new HashMap();
//        ans.put("path", pathAndNode.getPathSplit());
//        ans.put("node", pathAndNode.getNodeSplit());
//        ans.put("strategyOutput", strategyOutputList);
//        return ans;
//    }
//
//    @Override
//    public void save(Date date) throws IOException,ParseException {
//        Map<String, Object> economic = generate(date);
//        List<StrategyOutput> strategyOutputs = (List<StrategyOutput>) economic.get("strategyOutput");
//        saveAllStrategy(strategyOutputs);
//
//        // 组装HistoryData
//        List<HistoryData> historyDataList = new ArrayList<>();
//        // 第二天0点
//        Date tomorrow = DateUtils.getDateWithHour(DateUtils.plusOrMinusDay(date, 1).getTime(), 0).getTime();
//        String[] node = (String[]) economic.get("node");
//        String[] path = (String[]) economic.get("path");
//        historyDataList.add(new HistoryData(tomorrow, String.join(",", node), "node", StrategyEnums.COMFORT_TYPE.getType()));
//        historyDataList.add(new HistoryData(tomorrow, String.join(",", path), "path", StrategyEnums.COMFORT_TYPE.getType()));
//        saveAllHistoryData(historyDataList);
//    }
//}